using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication2.Models.Mapping
{
    public class SD_CourseMap : EntityTypeConfiguration<SD_Course>
    {
        public SD_CourseMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.ID)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.Name)
                .HasMaxLength(50);

            this.Property(t => t.Number)
                .HasMaxLength(20);

            this.Property(t => t.Status)
                .HasMaxLength(2);

            // Table & Column Mappings
            this.ToTable("SD_Course");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.Name).HasColumnName("Name");
            this.Property(t => t.Term).HasColumnName("Term");
            this.Property(t => t.Teacher).HasColumnName("Teacher");
            this.Property(t => t.Number).HasColumnName("Number");
            this.Property(t => t.CreatedBy).HasColumnName("CreatedBy");
            this.Property(t => t.CreatedOn).HasColumnName("CreatedOn");
            this.Property(t => t.Status).HasColumnName("Status");
            this.Property(t => t.Note).HasColumnName("Note");

            // Relationships
            this.HasOptional(t => t.Name1)
                .WithMany(t => t.SD_Course)
                .HasForeignKey(d => d.CreatedBy);
            this.HasOptional(t => t.SD_Teacher)
                .WithMany(t => t.SD_Course)
                .HasForeignKey(d => d.Teacher);
            this.HasOptional(t => t.SD_Term)
                .WithMany(t => t.SD_Course)
                .HasForeignKey(d => d.Term);

        }
    }
}
